<template>
  <div v-if="list.length!==0">
    <div class="footer">
      <div class="left">剩余{{ count }}个</div>
      <div class="mid">
        <!-- all -->
        <div
          @click="stateChange('all')"
          class="state-btn"
          :class="{ active: currentItem === 'all' }"
        >
          完成
        </div>
        <!-- incomplete -->
        <div
          @click="stateChange('incomplete')"
          class="state-btn"
          :class="{ active: currentItem === 'incomplete' }"
        >
          未完成
        </div>
        <!-- complete -->
        <div
          @click="stateChange('complete')"
          class="state-btn"
          :class="{ active: currentItem === 'complete' }"
        >
          已完成
        </div>
      </div>
      <div class="right" >
        <span v-if="removeShow" @click="removeComplete">清除已完成</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentItem: "all",
    };
  },
  // 父传子
  props: {
    list: {
      type: Array,
      required: true,
    },
  },
  computed: {
    // 显示清除按钮
    removeShow() {
      return this.list.some((e) => e.isDone);
    },
    count() {
      // // 根据list创建
      // let count = 0;
      // this.list.forEach((e) => {
      //   if (!e.isDone) {
      //     count++;
      //   }
      // });
      // return count;
      return this.list.filter((e) => !e.isDone).length;
    },
  },
  methods: {
    removeComplete() {
      this.$emit("removeComplete");
    },
    stateChange(name) {
      // 高亮
      this.currentItem = name;
      // 筛选
      this.$emit("stateChange", name);
    },
  },
};
</script>

<style lang='less' scoped>
.footer {
  height: 50px;
  padding: 5px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 0 5px #ccc;
  .mid {
    display: flex;
    .state-btn {
      cursor: pointer;
      padding: 5px;
      margin-right: 20px;
      &:last-child {
        margin: 0;
      }
      &.active {
        border: 1px solid turquoise;
      }
    }
  }
  .right {
    cursor: pointer;
  }
}
</style>